<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="chtml" uri="http://www.szhelper.com/jsp/html"%>
<%@ taglib  prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<chtml:script src="/js/ajaxfileupload.js" />
<title>新增站内信</title>
</head>
<body>
<div class="youarehere">网站内容管理 &gt; <span>管理站内信</span>&gt; <span>新增站内信</span></div>
<div id="layout_documentation" onclick="javascript: closeBar();">
<script type="text/javascript">
 	function valid4message(label, pattern, value, validEle, maskEle, isCheckNull){
		value = value.replace(/(^\s*)|(\s*$)/g, "");
		if(value.length > 0)
		{
			if(new RegExp(pattern).test(value))
			{
				$('#'+validEle+'').hide();
				$('#'+maskEle+'').hide();
				return true;
			}
			else
			{
				$('#'+validEle+'').html("<label>&nbsp;</label>"+label+"格式错误");
				$('#'+validEle+'').show();
				$('#'+maskEle+'').show();
				return false;
			};
		}
		else
		{
			if(isCheckNull == 'true')
			{
				$('#'+validEle+'').html("<label>&nbsp;</label>"+label+"不能为空");
				$('#'+validEle+'').show();
				$('#'+maskEle+'').show();
				return false;
			}
			else
			{
				$('#'+validEle+'').hide();
				$('#'+maskEle+'').hide();
				return true;
			}
		}
	}
	function isNull4message(label, eleName, validEle, maskEle){
		var flag=false;
		var checkvalue = $("input[name='"+eleName+"']");
		checkvalue.each(function()
		{
			if(this.checked==true)
			{
				flag = true;
			}
		});
		if(!flag)
		{
			$('#'+validEle+'').html("<label>&nbsp;</label>"+label+"不能为空");
			$('#'+validEle+'').show();
			$('#'+maskEle+'').show();
			return false;
		}
		else
		{
			$('#'+validEle+'').hide();
			$('#'+maskEle+'').hide();
			return true;
		}
	}
// message数据列表表单提交脚本
function _submitAction4message(obj, action, params)
{
		var submitForm;
		while ((obj.parentNode) && (obj.parentNode.tagName) && (!obj.parentNode.tagName.match(/FORM/i)))
		{
			obj = obj.parentNode;
		}
		submitForm = obj.parentNode;
		if(!submitForm)
		{
			submitForm = document.createElement("form");
			document.body.appendChild(submitForm);
		}
		submitForm.setAttribute("action", action);
		submitForm.setAttribute("method", "POST");
		for(var key in params)
		{
				var hiddenField = document.createElement("input");
				hiddenField.setAttribute("type", "hidden");
				hiddenField.setAttribute("name", key);
				hiddenField.setAttribute("value", params[key]);
				submitForm.appendChild(hiddenField);
		}
if(submit4message()) submitForm.submit();
}

function import_recevicer()
{
	var _file_name = $("#fileToUpload").val();
	if(_file_name == "" || _file_name.trim().length == 0)
	{
		alert("请选择要上传的文本.");
		return;
	}
	var _file_format = _file_name.substring(_file_name.lastIndexOf(".")+1,_file_name.length).toLowerCase();
	if(_file_format!="txt")
	{
		alert("不支持的文本格式.");
		return;
	}
	$.ajaxFileUpload(
		     {
		     url:'<chtml:path path="/" />message/upload',            
		     secureuri:false,
		     fileElementId:'fileToUpload',                     
		     dataType: 'json',                           
		     success: function (data, status)            
		   	 {  
				$("#receiver").val(data);    
		     },
		     error: function (data, status, e)            
		     {
		    	 alert("上传出错!"+e);
		         return;
		     }
		 });
}

</script>
<form id="message"  action="<chtml:path path="/" />message" method="post" onsubmit="return submit4message();">
<table class="data_table_main" style="margin-top: 0">
<tr>
<td background="<chtml:path path="/" />layout/list/tab_top.gif">
<!-- message标题头 -->
<table class="data_table_title">
<tr>
<td width="12" height="30"><img src="<chtml:path path="/" />layout/list/tab_left_top.gif" width="12" height="30" /></td><td align='left'><img src="<chtml:path path="/" />layout/list/list.gif" width="16" height="16" />新增</td>
<td align='right'>
&nbsp;
</td><td width="16"><img src="<chtml:path path="/" />layout/list/tab_right_top.gif" width="16" height="30" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="8" background="<chtml:path path="/" />layout/list/tab_left.gif">&nbsp;</td>
<td>
<!-- message数据区 -->
<table id="main_table4message" class="data_table_command" style="margin-top: 0">
<tr>
<td class="data_tab_tdr">标题</td>
<td class="data_tab_tdl"><input id="title" type="text" name="title" value="" />&nbsp;<span style="color:red;">*</span><span style="color:gray;font-style: italic;font-size: small;"></span>
<div id="mask4title" style="display: none;"></div>
<div id="valid4title" style="display: none;color: red;font-size: small;"></div>
</td>
</tr>
<tr>
<td class="data_tab_tdr">摘要</td>
<td class="data_tab_tdl"><input id="summary" type="text" name="summary" value="" />&nbsp;<span style="color:red;">*</span><span style="color:gray;font-style: italic;font-size: small;"></span>
<div id="mask4summary" style="display: none;"></div>
<div id="valid4summary" style="display: none;color: red;font-size: small;"></div>
</td>
</tr>
<tr>
<td class="data_tab_tdr">内容</td>
<td class="data_tab_tdl"><textarea id="content" name="content" ></textarea>&nbsp;<span style="color:red;">*</span><span style="color:gray;font-style: italic;font-size: small;"></span>
<div id="mask4content" style="display: none;"></div>
<div id="valid4content" style="display: none;color: red;font-size: small;"></div>
</td>
</tr>
<tr>
<td class="data_tab_tdr">发送类型</td>
<td class="data_tab_tdl"><select id="sendType" name="sendType"  onchange = "javascript:changeSendType();">
<option value='ALLMEMBER'>所有用户</option>
<option value='SINGLEMEMBER'>单个用户</option>
</select>&nbsp;&nbsp;
<input type="checkbox" name="set_timing" id="set_timing" onclick="javascript:setSendTime();" value="true"/>定时发信 &nbsp;&nbsp;
<input type="text" id="sendtime" name="sendtime" readonly="readonly" style="display: none;" />
<img id="dateimg1" src="<chtml:path  path="/" />images/calendar2.gif" style="display: none;" />
<script type="text/javascript">Calendar.showDate("sendtime","dateimg1");</script>
</td>
</tr>
<tr id="filter_condition_tr" style="display: none;">
<td class="data_tab_tdr">筛选要发送的用户 :</td>
<td class="data_tab_tdl">
	<table border="0">
	 <tr>
		<td>开始时间：</td><td><input type="text" id="begintime" name="begintime" readonly="readonly" />
		<img id="dateimg2" src="<chtml:path  path="/" />images/calendar2.gif"/>
		<script type="text/javascript">Calendar.showDate("begintime","dateimg2");</script>
		</td>
		<td>结束时间：</td><td><input type="text" id="endtime" name="endtime" readonly="readonly" />
		<img id="dateimg3" src="<chtml:path  path="/" />images/calendar2.gif"/>
		<script type="text/javascript">Calendar.showDate("endtime","dateimg3");</script>
		</td>
	 </tr>
	 <tr>
	 	 <td colspan="4"><input type="radio" id="newmember" name="conditonType" value="NEWREGIST"/>新用户:该时间段内新的注册用户</td>
	 </tr>
	 <tr>
		  <td colspan="4"><input type="radio" id="unantemember" name="conditonType" value="TOTALANTEMONEYO"/>沉默用户:该段时间内曾经登录过网站且"累计投资额=0"的用户</td>
	 </tr>
	 <tr>
		  <td colspan="4">
		  <input type="radio" id="byimprest" name="conditonType" value="TOTALIMPRESTMONEY"/>根据该时间段内累计充值额范围筛选用户&nbsp;&nbsp;&nbsp;&nbsp;从
		  &nbsp;<input type="text" id="minimprest" name="minimprest" value=""  />元&nbsp;到&nbsp;<input type="text" id="maximprest" name="maximprest" value=""  />元
		  </td>
	 </tr>
	  <tr>
		  <td colspan="4">
		  <input type="radio" id="byante" name="conditonType" value="TOTALANTEMONEY"/>根据该时间段内累计投资额范围筛选用户&nbsp;&nbsp;&nbsp;&nbsp;从
		  &nbsp;<input type="text" id="minante" name="minante" value=""  />元&nbsp;到&nbsp;<input type="text" id="maxante" name="maxante" value=""/>元
		  </td>
	 </tr>
	</table>
</td>
</tr>
<tr id="receiver_tr" style="display: none;">
<td class="data_tab_tdr">收件人 :</td>
<td class="data_tab_tdl">
	<table border="0">
		<tr>
			<td>选择导入文本：<input type="file" id="fileToUpload" name="fileToUpload" value=""/>&nbsp;&nbsp;<input type="button" onclick="javascript:import_recevicer();" id="importsbt" value="导入"/></td>
		</tr>
		<tr>
			<td><textarea id="receiver" name="receiver" cols="90" rows="5">在输入框中输入收件人的用户名，中间用";"隔开，也可以通过.txt格式导入收件人</textarea></td>
		</tr>
	</table>
</td>
</tr>
<tr>
<td colspan="2" align="center" height="25" class="data_tab_td">
<button type="button" onclick="javascript:void(_submitAction4message(this,'<chtml:path path="/" />message?isPublish=NO',{}));return false;"  />保存</button>&nbsp;&nbsp;
<button type="button" onclick="javascript:void(_submitAction4message(this,'<chtml:path path="/" />message?isPublish=YES',{}));return false;"  />发布</button>&nbsp;&nbsp;
<button onclick="javascript:void(history.back(-1));" type=button>返回</button>&nbsp;&nbsp;
</td>
</tr>
</table>
</td>
<td width="8" background="<chtml:path path="/" />layout/list/tab_right.gif">&nbsp;</td> </tr>
</table>
</td>
</tr>
<tr>
<td background="<chtml:path path="/" />/layout/list/tab_bottom.gif">
<table class="data_table_pagination" align='center' cellpadding='0' cellspacing='0'>
<tr><td width="12" height="35"><img src="<chtml:path path="/" />layout/list/tab_left_bottom.gif" width="12" height="35" /></td><td>&nbsp;</td><td width="16"><img src="<chtml:path path="/" />layout/list/tab_right_bottom.gif" width="16" height="35" /></td></tr></table>
</td>
</tr>
</table>
<!-- message结束 -->
<input id="id" type="hidden" name="id" value="" />
<input id="version" type="hidden" name="version" value="0" />
</form>
<script type="text/javascript">
	function changeSendType(){
		var send_type = $("#sendType").val();
		if(send_type == "ALLMEMBER")
		{
			$("#filter_condition_tr").hide();
			$("#receiver_tr").hide();
		}
		else if(send_type == "SINGLEMEMBER")
		{
			$("#filter_condition_tr").hide();
			$("#receiver_tr").show();
		}
	}
	function setSendTime(){
		if($("#set_timing").attr("checked"))
		{
			$("#sendtime").show();
			$("#dateimg1").show();
		}
		else
		{
			$("#sendtime").hide();
			$("#dateimg1").hide();
		}
	}
 	function submit4message(){
		var validResult = true;
		if(validResult){
			validResult = valid4message('标题','^[\\s\\S]*$',$('#title').val(),'valid4title', 'mask4title', 'true');
		}
		if(validResult){
			validResult = valid4message('摘要','^[\\s\\S]*$',$('#summary').val(),'valid4summary', 'mask4summary', 'true');
		}
		if(validResult){
			validResult = valid4message('内容','^[\\s\\S]*$',$('#content').val(),'valid4content', 'mask4content', 'true');
		}
		if(validResult){
			validResult = valid4message('发送类型','^[\\s\\S]*$',$('#sendType').val(),'valid4sendType', 'mask4sendType', 'true');
		}
		if(validResult){
			validResult = sbtcheck();
		}
		return validResult;
	}
	function sbtcheck()
	{
		var __sendType = $("#sendType").val();
		if($("#set_timing").attr("checked"))
		{
			if($("#sendTime").val() == "")
			{
				alert("请设置定时发送时间!");
				return false;
			}
		}
		if(__sendType == "SINGLEMEMBER")
		{
			if($("#receiver").val()=="" || $("#receiver").val().trim().length == 0)
			{
					alert("收件人不能为空!");
					return false;
			}
		}
		return true;
	}
	new ResizeWidget('main_table4message');
</script>
</div>
<!--说明   -->	
<div class="sm_info">
	<p class="row_one">说明：</p>
	<p class="other"></p>
	<p class="other"></p>
</div>
</body>
</html>